* FIGURE 1

clear all
set seed 123456
set obs 100 // simulate number of months
gen y0 = 0 // initial portfolio
gen epsilon = 0 // residual portfolio regression

* name time period "t"
gen t = _n
tsset t

************************************************
*** EXPECTED EXCESS RETURN BLOCK
*** ar coefficient
gen rhofrictions = 0.87 // delta = 0.93
gen rhofrictionsless = 0.51 

*** standard deviation residual
gen nufrictions = 0.00076*(t == 2)
gen nufrictionsless = 0.0017*(t == 2)
************************************************

************************************************
*** PORTFOLIO EQUATION BLOCK
*** coefficients
gen a1frictions = 0.88
gen a2frictions = 19.6

gen a1frictionsless = 0
gen a2frictionsless = 58.14

gen nu = 0 // residual excess return
gen er = 0 // initiate variable
************************************************

************************************************
*** IRF
global ffless "frictions frictionsless"
foreach m of global ffless {
	
	* initiate excess return 2 scenarios
	qui gen er`m' = er
	qui gen er`m'2 = er
	
	* dynamic excess return
	replace er`m' = rho`m'*l.er`m' + nu if _n > 1
	replace er`m'2 = rho`m'*l.er`m'2 + nu`m' if _n > 1

	* portfolio reacation
	gen y`m' = y0 
	replace y`m' = a1`m'*l.y`m' + a2`m'*er`m' + epsilon if _n > 1
	
	gen y`m'2 = y0
	replace y`m'2 = a1`m'*l.y`m'2 + a2`m'*er`m'2 + epsilon if _n > 1

	gen irf`m' = 100*(y`m'2 - y`m')

}

twoway (line irffrictionsless irffrictions t, lcolor(gs10 black ) lwidth(medthick medthick) lpattern(dash solid)) , graphregion(color(white)) xtitle(" " "Months") legend(ring(0) pos(2) col(1) label(1 "Without Portfolio Frictions, {&gamma} = 10") label(2 "With estimated Portfolio Frictions")) ytitle("") 
graph export "$figpath\fig1.eps", replace